package com.bezdelnick.forum.web.component;

import com.bezdelnick.forum.domain.Answer;
import com.bezdelnick.forum.domain.Question;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import java.util.Arrays;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 16.08.12
 * Time: 9:57
 * To change this template use File | Settings | File Templates.
 */
public class AnswersListView extends ListView {
    final List<String> keys = Arrays.asList("answer", "adding");

    public AnswersListView(String id, List list) {
        super(id, list);
    }

    @Override
    protected void populateItem(ListItem listItem) {
        final Answer answer = (Answer) listItem.getModelObject();

        listItem.add(new ListView("cells", keys) {

            @Override
            protected void populateItem(ListItem item) {

                switch (item.getIndex()) {
                    case 0:
                        item.add(new LinkWithText("cell_1", "#", answer.getTextAnswer()));
                        item.add(new Label("cell_2", ""));
                        break;
                    case 1:
                        item.add(new Label("cell_1", String.valueOf(answer.getUserId())));
                        item.add(new Label("cell_2", answer.getDatePublication().toString()));
                        break;
                }
            }
        });
    }
}
